package com.demo.java8Stream;

public class TestDesc {

  /*  public static void main(String[] args) throws UnknownHostException, SocketException {

        16         List<Map<String, Object>> listResult = new ArrayList<Map<String, Object>>();
        17         Map<String, Object> map1 = new LinkedHashMap<String, Object>();
        18         map1.put("count", 2);
        19         map1.put("name", "abc");
        20         map1.put("key", "acv");
        21         listResult.add(map1);
        22         Map<String, Object> map2 = new LinkedHashMap<String, Object>();
        23         map2.put("count", 3);
        24         map2.put("name", "bbc");
        25         map2.put("key", "bcv");
        26         listResult.add(map2);
        27         Map<String, Object> map3 = new LinkedHashMap<String, Object>();
        28         map3.put("count", 1);
        29         map3.put("name", "cbc");
        30         map3.put("key", "ccv");
        31         listResult.add(map3);
        32         Map<String, Object> map4 = new LinkedHashMap<String, Object>();
        33         map4.put("count", 4);
        34         map4.put("name", "cbc");
        35         map4.put("key", "ccv");
        36         listResult.add(map4);
        37
        38         System.out.println("排序前：");
        39         for (Map<String, Object> map : listResult) {
            40             System.out.println("count:"+map.get("count")+" name:"+map.get("name")+" key:"+map.get("key"));
            41         }
        42
        43         Collections.sort(listResult, new MapComparatorDesc());
        44
        45         System.out.println("降序：");
        46         for (Map<String, Object> map : listResult) {
            47             System.out.println("count:"+map.get("count")+" name:"+map.get("name")+" key:"+map.get("key"));
            48         }
        49
        50         Collections.sort(listResult, new MapComparatorAsc());
        51
        52         System.out.println("升序：");
        53         for (Map<String, Object> map : listResult) {
            54             System.out.println("count:"+map.get("count")+" name:"+map.get("name")+" key:"+map.get("key"));
            55         }
        56     }
      static class MapComparatorDesc implements Comparator<Map<String, Object>> {
          @Override
          public int compare(Map<String, Object> m1, Map<String, Object> m2) {
                          Integer v1 = Integer.valueOf(m1.get("count").toString());
                          Integer v2 = Integer.valueOf(m2.get("count").toString());
                          if (v2 != null) {
                                  return v2.compareTo(v1);
                              }
                          return 0;
                      }

              }
      static class MapComparatorAsc implements Comparator<Map<String, Object>> {
70         @Override
71         public int compare(Map<String, Object> m1, Map<String, Object> m2) {
            72             Integer v1 = Integer.valueOf(m1.get("count").toString());
            73             Integer v2 = Integer.valueOf(m2.get("count").toString());
            74             if(v1 != null){
                75                 return v1.compareTo(v2);
                76             }
            77             return 0;
            78         }
79
        80     }*/
}
